{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# many cells\n",
    "This notebook demonstrates lgo can handle thousands of cells though lgo builds and loads shared objects file on every executions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import (\n",
    "    \"fmt\"\n",
    "    \"strings\"\n",
    "    \"time\"\n",
    ")\n",
    "\n",
    "interval := 64\n",
    "start := time.Now()\n",
    "var sum int64\n",
    "var msgs []string"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "{\n",
    "    n := 1\n",
    "    sum += int64(n)\n",
    "    if n % interval == 0 {\n",
    "        end := time.Now()\n",
    "        msgs = append(\n",
    "            msgs,\n",
    "            fmt.Sprintf(\"cycle: [%d, %d], took %v on average\", n - interval + 1, n, end.Sub(start)/time.Duration(interval)))\n",
    "        start = end\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "{\n",
    "    n := 2\n",
    "    sum += int64(n)\n",
    "    if n % interval == 0 {\n",
    "        end := time.Now()\n",
    "        msgs = append(\n",
    "            msgs,\n",
    "            fmt.Sprintf(\"cycle: [%d, %d], took %v on average\", n - interval + 1, n, end.Sub(start)/time.Duration(interval)))\n",
    "        start = end\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Note\n",
    "Many cells are omitted from this notebook to keep the size small. To get a complete version, run make_many_cells.ipnb in the same dir."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1024,
   "metadata": {},
   "outputs": [],
   "source": [
    "{\n",
    "    n := 1023\n",
    "    sum += int64(n)\n",
    "    if n % interval == 0 {\n",
    "        end := time.Now()\n",
    "        msgs = append(\n",
    "            msgs,\n",
    "            fmt.Sprintf(\"cycle: [%d, %d], took %v on average\", n - interval + 1, n, end.Sub(start)/time.Duration(interval)))\n",
    "        start = end\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1025,
   "metadata": {},
   "outputs": [],
   "source": [
    "{\n",
    "    n := 1024\n",
    "    sum += int64(n)\n",
    "    if n % interval == 0 {\n",
    "        end := time.Now()\n",
    "        msgs = append(\n",
    "            msgs,\n",
    "            fmt.Sprintf(\"cycle: [%d, %d], took %v on average\", n - interval + 1, n, end.Sub(start)/time.Duration(interval)))\n",
    "        start = end\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1026,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "524800\n"
     ]
    }
   ],
   "source": [
    "sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1027,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cycle: [1, 64], took 684.526294ms on average\n",
      "cycle: [65, 128], took 672.778457ms on average\n",
      "cycle: [129, 192], took 681.855261ms on average\n",
      "cycle: [193, 256], took 674.783885ms on average\n",
      "cycle: [257, 320], took 686.477005ms on average\n",
      "cycle: [321, 384], took 683.289412ms on average\n",
      "cycle: [385, 448], took 687.293805ms on average\n",
      "cycle: [449, 512], took 693.450195ms on average\n",
      "cycle: [513, 576], took 672.261078ms on average\n",
      "cycle: [577, 640], took 682.784516ms on average\n",
      "cycle: [641, 704], took 691.448044ms on average\n",
      "cycle: [705, 768], took 671.875065ms on average\n",
      "cycle: [769, 832], took 673.786842ms on average\n",
      "cycle: [833, 896], took 681.162642ms on average\n",
      "cycle: [897, 960], took 672.475553ms on average\n",
      "cycle: [961, 1024], took 680.732248ms on average\n",
      "765\n",
      "<nil>\n"
     ]
    }
   ],
   "source": [
    "fmt.Println(strings.Join(msgs, \"\\n\"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Go (lgo)",
   "language": "go",
   "name": "lgo"
  },
  "language_info": {
   "file_extension": "",
   "mimetype": "",
   "name": "go",
   "version": ""
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
